package com.itheima.dubbo.service;

import com.itheima.dubbo.UserInterface;
import com.itheima.dubbo.pojo.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;

/**
 * 冪等性操作：无论多少次请求，得到的最终结果是一致的
 * 冪等：查询、修改（表单提交）、删除
 * 非冪等：新增
 * @Description:
 * @Version: V1.0
 */
//@DubboService(timeout = 3000, retries = 0, version = "2.0.0")   // 注册服务
//@DubboService(loadbalance = "roundrobin")   // 注册服务
//@DubboService(cluster = "failfast")  容错机制， 默认是 failover
@DubboService
public class UserServiceImpl implements UserInterface {

    /**
     * dubbo接口方法
     * @param username
     * @return
     */
    @Override
    public String hello(String username) {

        System.out.println("UserServiceImpl ...2.0..");
//
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        String attachment = RpcContext.getContext().getAttachment("username");


        return "Hello Dubbo...name: " + username;
    }

    @Override
    public User findUser(User user) {

        System.out.println("参数： " + user);

        user.setUsername("lisi");
        user.setAge(20);

        return user;
    }
}
